<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\model\learn;
use app\api\service\User as UserService;
use app\common\model\learn\ChatLog as ChatLogModel;
use think\facade\Db;
/**
 *
 * Class Article
 * @package app\api\model
 */
class ChatLog extends ChatLogModel {

	public function add($data) {
		$data['store_id'] = self::$storeId;
		$data['user_id'] = UserService::getCurrentLoginUserId();


		$this->save($data);

		return $data;
	}

	public function getList($params) {
		$userId = UserService::getCurrentLoginUserId();
		$filter = [];
		if (isset($params['lastMessageId'])) {
			$filter[] = ['log_id', '<', $params['lastMessageId']];
		}
		$list = $this
			->where('chat_id', $params['chatId'])
			->where($filter)

			->order(['create_time' => 'desc'])
			->limit(10)
			->select();

		return $list;

	}

}